package com.songlanyun.modules.distributionconfig.entity;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.distributionconfig.model.value.ProxyGoodsRule;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
 * 平台商家代销商品小程序分佣配置
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-12-22 11:43:24
 */
@Data
@TableName("yxt_distribution_shop_proxy_config")
public class DistributionShopProxyConfig extends RootEntity<Long,DistributionShopProxyConfig> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	private Long id;
	/**
	 * 商家id
	 */
	@NotNull(message = "商家id必须给")
	private Long shopId;
	/**
	 * 是否开启分佣
	 */
	private Boolean open;
	/**
	 * 规则配置字符串
	 */
	@JsonIgnore
	private String ruleConfig;

	public void setRuleConfig(String ruleConfig)
	{
		this.ruleConfig = ruleConfig;
		try {
			this.proxyGoodsRule  = ClassConvertUtils.stringToClassSnake(ruleConfig, new TypeReference<ProxyGoodsRule>() {
			});
		} catch (IOException e) {
			throw new RRException("规则配置字符串无法转成ProxyGoodsRule");
		}
	}

	/**
	 * 规则配置模型数据
	 */
	@TableField(exist = false)
	private ProxyGoodsRule proxyGoodsRule;
	public void setProxyGoodsRule(ProxyGoodsRule proxyGoodsRule) {
		this.proxyGoodsRule = proxyGoodsRule;
		this.ruleConfig =  ClassConvertUtils.transformJSONToSnake(proxyGoodsRule);


	}







	@TableField(fill = FieldFill.INSERT)
	private Date createTime;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updateTime;

	@Override
	public Long getIdentity() {
		return getId();
	}
}
